<template>
  <div>
    <div class="flex">
      <div>
        <el-form :inline="true" :model="where" label-position="top">
          <el-form-item>
            <el-input v-model="whereType.value" clearable>
              <template #prepend>
                <el-select v-model="whereType.key" style="width:120px">
                  <el-option :label="plugin.lang('form.name')" value="name"></el-option>
                  <el-option :label="plugin.lang('form.phone')" value="phone"></el-option>
                  <el-option :label="plugin.lang('form.code')" value="code"></el-option>
                  <el-option :label="plugin.lang('form.email')" value="email"></el-option>
                </el-select>
              </template>
            </el-input>
          </el-form-item>
          <el-form-item>
            <el-select v-model="where.type" style="width:120px" clearable>
              <el-option
                v-for="(item, index) in plugin.langTm('form.type_text')"
                :key="index"
                :label="item"
                :value="index">
              </el-option>
            </el-select>
          </el-form-item>
          <el-form-item>
            <el-button type="primary" @click="model.page(1)" plain>
              <template #icon>
                <i class="iconfont min icon-search-max"></i>
              </template>
            </el-button>
          </el-form-item>
        </el-form>
      </div>
      <div>
        <el-button type="primary" @click="form.open({})">
          {{ lang.t('common.create') }}
          <template #icon>
            <i class="iconfont mini icon-add-max"></i>
          </template>
        </el-button>
      </div>
    </div>
    <Table @form="data => form.open(data)" @point="data => point.open(data)"/>
    <div class="page">
      <el-pagination
        @current-change="model.page"
        :current-page="where.page"
        :page-size="where.page_size"
        layout="total, prev, pager, next, jumper"
        :total="where.page_total"
        background>
      </el-pagination>
    </div>
    <Form ref="form" />
    <Point ref="point" />
  </div>
</template>
<script>
import { ref } from 'vue'
import app from '@/app'
import model from '../../model'

import Table from './table'
import Form from './form'
import Point from './point'

export default {
  components: {
    Table,
    Form,
    Point
  },
  setup() {
    // 条件
    const where = model.data

    // 查询方式
    const whereType = model.where

    // 表单
    const form = ref(null)

    // 积分
    const point = ref(null)

    // 加载列表
    model.get()

    return {
      lang: app.lang,
      plugin: app.plugin.index,
      model,
      where,
      whereType,
      form,
      point
    }
  }
}
</script>